#ifndef _SEGGER_H_
#define _SEGGER_H_

#include "slab.h"
#include "datrie.h"
#include "list.h"

#define SEG_LEN_MAX		(1<<24)
#define TEXT_BUF_SIZE   (1<<18)
#define MM_LIST_SIZE    (128)

typedef struct tok{
	struct list_head list;
	unsigned short len;
	unsigned int tag;
	unsigned int freq;
} tok;

typedef struct chunk{
	struct list_head list;
	tok * t1;
	tok * t2;
	tok * t3;
	unsigned short len;			//total len of t1, t2, t3
	unsigned char size;			//not NULL tok num
} chunk;

typedef struct thunk{
	struct list_head chunks;
	unsigned short size;		//chunk left
	unsigned short max_len;		//max_len of chunks
} thunk;

typedef struct segger{
	unsigned int off;			//cur offset 1.used when segger_do 2.used when segger_next_res
	unsigned int len;			//input buf len
	struct list_head res;		//res list
	struct list_head * res_;	//next res pos for segger_next_res
	const char * buf;			//input buf
	vla * mm;					//vla of struct list_head *
	slab * slabp;				//slab
	dat *datp;					//double array trie
	unsigned char div_flag;		//div flag for segger_next_res when divmap is avalid
	unsigned char hoov_flag;	//set it for hoov when meet HP
	unsigned char busy;			//if busy					--only used in hiseg
	struct list_head list;		//list as a node of hiseg   --only used in hiseg
}segger;

segger * segger_new(dat * datp);
int segger_do(segger * p, char * input, unsigned int len);
const char * segger_next_res(segger * p, unsigned int * lenp);
int segger_free(segger * p);

/* error code list */
#define SEG_OK				(0)
#define SEG_EMPTY			(1)

#define SEG_INPUT_ERR		(-1)
#define SEG_DECODE_ERR		(-2)
#define SEG_PUSHTOK_ERR		(-3)
#define SEG_TOKCRUSH_ERR	(-4)
#define SEG_PUSHMM_ERR		(-10)
#define SEG_DATFETCH_ERR	(-20)
#define SEG_MMSEG_ERR		(-100)

#endif
